package demo5;
class Money implements Cloneable{
    public int m = 100;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    public String name;
    public Money money = new Money();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student student = (Student) super.clone();
        student.money = (Money) this.money.clone();
        return student;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", money=" + money +
                '}';
    }
}
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException{
        Student student = new Student();
        student.name = "李华";
        Student student1 = (Student) student.clone();
        student1.name = "张三";
        student1.money.m = 999;
        System.out.println("student :" + student.name + " " + student.money.m);
        System.out.println("student1 :" + student1.name + " " + student1.money.m);
    }
}
